package com.smartcruise.main.selfFragment.setting.offlineMap;

import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

/**
 * ViewPager数据
 */
public class OfflinePagerAdapter extends PagerAdapter {

    private View mOfflineMapAllList;
    private View mOfflineDownloadedList;

    private ViewPager mContentViewPager;

    public OfflinePagerAdapter(ViewPager contentViewPager, View offlineMapAllList, View offlineDownloadedList) {
        mContentViewPager = contentViewPager;
        this.mOfflineMapAllList = offlineMapAllList;
        this.mOfflineDownloadedList = offlineDownloadedList;
    }

    @Override
    public void destroyItem(View arg0, int arg1, Object arg2) {
        if (arg1 == 0) {
            mContentViewPager.removeView(mOfflineMapAllList);
        } else {
            mContentViewPager.removeView(mOfflineDownloadedList);
        }
    }

    @Override
    public void finishUpdate(View arg0) {
    }

    @Override
    public int getCount() {
        return 2;
    }

    @Override
    public Object instantiateItem(View arg0, int arg1) {

        if (arg1 == 0) {
            mContentViewPager.addView(mOfflineMapAllList);
            return mOfflineMapAllList;
        } else {
            mContentViewPager.addView(mOfflineDownloadedList);
            return mOfflineDownloadedList;
        }

    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == (arg1);
    }

    @Override
    public void restoreState(Parcelable arg0, ClassLoader arg1) {
    }

    @Override
    public Parcelable saveState() {
        return null;
    }

    @Override
    public void startUpdate(View arg0) {
    }

}
